1 /*
2 * Angkor Web Framework
3 *
4 * Distributable under LGPL license.
5 * See terms of license at gnu.org.
6 */
7
8 package com.tirsen.angkor.table;
9
10 import com.tirsen.angkor.event.ChangeListener;
11 import com.tirsen.angkor.event.ChangeSourceHelper;
12
13
14 /***
15 * @author $Author: tirsen $
16 * @version $Revision: 1.5 $
17 * <BR>
18 * $Id: AbstractTableModel.java,v 1.5 2002/10/09 21:37:37 tirsen Exp $
19 */
20 public abstract class AbstractTableModel implements TableModel
21 {
22 private int start = 0;
23 private int end = -1;
24 private int rowCount = -1;
25 private ChangeSourceHelper changeSourceHelper = new ChangeSourceHelper(this);
26
27 /***
28 * Sets the actual row count of this model. Values needs to be fetched beforehand for rows actually used by
29 * the user of the model. If set to -1 the size of actual data is used instead.
30 */
31 public void setRowCount(int rowCount)
32 {
33 this.rowCount = rowCount;
34 }
35
36 public int getRowCountInRange()
37 {
38 return getEnd() - getStart() + 1;
39 }
40
41 public int getRowCount()
42 {
43 return rowCount;
44 }
45
46 /***
47 * If any number is set to a negative number it is subtracted from the number of rows.
48 * As a special case of this setting end to -1 sets the range to the last row.
49 */
50 public void setRange(int start, int end)
51 {
52 this.start = start;
53 this.end = end;
54 }
55
56 public int getStart()
57 {
58 System.out.println("start = " + start);
59 System.out.println("normalize(start) = " + normalize(start));
60 return normalize(start);
61 }
62
63 public int getEnd()
64 {
65 return normalize(end);
66 }
67
68 private int normalize(int row)
69 {
70 int rows = getRowCount();
71 if (rows == 0)
72 row = 0;
73 else
74 {
75 if (row < 0) row = rows + row;
76 if (row >= rows) row = rows - 1;
77 }
78 return row;
79 }
80
81 public void empty()
82 {
83 setRowCount(-1);
84 setRange(0, -1);
85 }
86
87 public void addChangeListener(ChangeListener listener)
88 {
89 changeSourceHelper.addChangeListener(listener);
90 }
91
92 public void removeChangeListener(ChangeListener listener)
93 {
94 changeSourceHelper.removeChangeListener(listener);
95 }
96
97 /***
98 * Call this method when values of the model has changed, will fire a change event.
99 */
100 protected void signalChanged()
101 {
102 changeSourceHelper.signalChangeEvent();
103 }
104 }
This page was automatically generated by Maven